package _35SearchInsertPosition;

public class CSolution {

    public static void main(String[] args) {
        System.out.println("aa");
        System.out.println(searchInsert(new int[]{1, 3}, 3));
    }

    private static int searchInsert(int[] nums, int target) {
        if (nums == null || nums.length == 0 || nums[0] >= target) {
            return 0;
        }
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == target) {
                return i;
            }
            if (nums[i] < target && nums[i + 1] > target) {
                return i + 1;
            }
        }
        if (nums[nums.length - 1] == target) {
            return nums.length - 1;
        }
        return nums.length;
    }
}
